package org.jiuling.wechat.publicplatform.api.enums;

import org.jiuling.local.tools.verify.StringVerify;
import org.jiuling.network.tools.http.request.enums.RequestMethodEnum;
import org.jiuling.wechat.publicplatform.model.*;

/**
 * 微信API枚举
 * @author 紫灵
 * @date 2022年04月21日 18时18分28秒
 */
public enum WeChatApiEnum {

    CGIBIN_TOKEN("获取Token","/cgi-bin/token", RequestMethodEnum.GET, "appid,grant_type,secret",null, null,AccessToken.class),
    CGIBIN_OPENAPI_QUOTA_GET("开放API限额查询","/cgi-bin/openapi/quota/get",RequestMethodEnum.POST,"access_token","cgi_path","quota", Quota.class),
    CGIBIN_OPENAPI_RID_GET("查询Rid","/cgi-bin/openapi/rid/get",RequestMethodEnum.POST,"access_token","rid","request",RidInfo .class),
    CGIBIN_CLEARQUOTA("清除限额","/cgi-bin/clear_quota",RequestMethodEnum.POST,"access_token","appid",null,null),
    GET_API_DOMAIN_IP("获取api区域Ip","/cgi-bin/get_api_domain_ip",RequestMethodEnum.POST,"access_token",null,"ip_list", String.class),
    GET_USER("获取用户列表","/cgi-bin/user/get",RequestMethodEnum.GET,"access_token",null,null, OpenIdList.class),
    USER_INFO("获取用户信息","/cgi-bin/user/info",RequestMethodEnum.GET,"access_token,openid",null,null, UserInfo.class),
    MESSAGE_TEMPLATE_SEND("发送末班消息","/cgi-bin/message/template/send",RequestMethodEnum.POST,"access_token","touser,template_id,data","msgid", String.class);


    private final String path = "https://api.weixin.qq.com";
    /** 请求地址 */
    private final String url;
    /** 请求名称 */
    private final String name;
    /** 请求方式 */
    private final RequestMethodEnum requestMethod;
    /** 请求参数 */
    private final String paramName;
    /** 请求内容 */
    private final String bodyName;
    /** 返回类 */
    private final Class<?> clazz;
    /** 解析参数名 */
    private final String analysisParamName;

    WeChatApiEnum(String name,String url,RequestMethodEnum requestMethod, String paramName, String bodyName,String analysisParamName,Class<?> clazz) {
        this.url = url;
        this.name = name;
        this.requestMethod = requestMethod;
        this.paramName = paramName;
        this.bodyName = bodyName;
        this.clazz = clazz;
        this.analysisParamName = analysisParamName;
    }

    public String getUrl() {
        return path+url;
    }

    public String getName() {
        return name;
    }

    public RequestMethodEnum getRequestMethod() {
        return requestMethod;
    }

    public String[] getParamName() {
        if(StringVerify.isBlank(paramName)){
            return null;
        }else {
            return paramName.split(",");
        }
    }

    public String[] getBodyName() {
        if(StringVerify.isBlank(bodyName)){
            return null;
        }else {
            return bodyName.split(",");
        }
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public String getAnalysisParamName() {
        return analysisParamName;
    }
}
